﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;

namespace Model
{
    /// <summary>
    /// Dll帮助类
    /// </summary>
    public static class DllHelper
    {
        /// <summary>
        /// 获取当前程序集中所有类型
        /// </summary>
        /// <returns></returns>
        public static Assembly GetCurrentAssembly()
        {
            return typeof(Game).Assembly;
        }

        /// <summary>
        /// 获取热更新程序集
        /// </summary>
        /// <returns></returns>
        public static Assembly GetHotfixAssembly()
        {
            string basePath = AppDomain.CurrentDomain.BaseDirectory;
            byte[] dllBytes = File.ReadAllBytes(basePath + "./Hotfix.dll");
            byte[] pdbBytes = File.ReadAllBytes(basePath + "./Hotfix.pdb");
            Assembly assembly = Assembly.Load(dllBytes, pdbBytes);
            return assembly;
        }

        /// <summary>
        /// 获取所有程序集中的所有类型
        /// </summary>
        /// <returns></returns>
        public static List<Type> GetAllTypes()
        {
            List<Type> list = new List<Type>();
            foreach (var item in ObjectEvents.Instance.GetAll())
            {
                list.AddRange(item.GetTypes());
            }
            return list;
        }
    }
}
